package com.gitee.aurora.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * author: jiangfuxiao
 * Date:2022/9/6 9:30
 */
public class DataBaseMappingUtil {

    public static boolean checkSqlDDL(String sql) {
        if (StringUtils.isEmpty(sql)) {
            return false;
        } else {
            List<String> tempList = splitSql(sql);
            if (tempList.isEmpty()) {
                return false;
            } else {
                return !" SELECT ".trim().equalsIgnoreCase(((String)tempList.get(0)).toUpperCase().trim()) && !" SHOW ".trim().equals(((String)tempList.get(0)).toUpperCase().trim()) && !" DESC ".trim().equals(((String)tempList.get(0)).toUpperCase().trim());
            }
        }
    }

    public static List<String> splitSql(String sql) {
        if (StringUtils.isEmpty(sql)) {
            String[] arraylist = sql.split(" ");
            List<String> list = new ArrayList();
            String[] var3 = arraylist;
            int var4 = arraylist.length;

            for(int var5 = 0; var5 < var4; ++var5) {
                String tempValue = var3[var5];
                if (StringUtils.isNotEmpty(tempValue) && !tempValue.trim().equals(" ( ".trim())) {
                    list.add(tempValue.trim());
                }
            }

            return list;
        } else {
            return Collections.emptyList();
        }
    }
}
